package Com.amit.synchronization;

public class Lab3 {

	
	public static void main(String[] args) {
		
		final String resource1="amit";
		final String resource2="yadav";
		
		Thread t1=new Thread(){
				public void run()
				{
					synchronized (resource1) {
						System.out.println("The resource1 is locked by thread1");
						
						try
						{
							Thread.sleep(500);
						}
						catch (Exception e) {
							
							System.out.println(e);
						}
						
						synchronized (resource2) {

							System.out.println("The resource2 is locked by thread1");
							
						}
					}
					
				}
		};
		
		Thread t2=new Thread(){
			public void run()
			{
				synchronized (resource2) {
					System.out.println("The resource2 is locked by thread2");
					
					try
					{
						Thread.sleep(500);
					}
					catch (Exception e) {
						
						System.out.println(e);
					}
					
					synchronized (resource1) {

						System.out.println("The resource1 is locked by thread2");
						
					}
				}
				
			}
	};
		
		t1.start();
		t2.start();
		
		
	}

}
